'''
Author: luqinghua
Date: 2025-04-24 11:10:20
LastEditors: luqinghua
LastEditTime: 2025-04-24 11:10:27
FilePath: \rpa-client\test\win-lock.py
Description: 
'''
import webview
import ctypes

# 定义 Windows API 常量
ES_CONTINUOUS = 0x80000000
ES_DISPLAY_REQUIRED = 0x00000002

def prevent_screen_lock():
    # 调用 Windows API 设置电源状态，防止屏幕锁定
    ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED)

def allow_screen_lock():
    # 恢复默认的电源状态，允许屏幕锁定
    ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS)

def main():
    # 在窗口显示前防止屏幕锁定
    prevent_screen_lock()

    # 创建一个简单的 WebView 窗口
    window = webview.create_window('My WebView', 'https://www.example.com')
    webview.start()

    # 在窗口关闭后允许屏幕锁定
    allow_screen_lock()

if __name__ == "__main__":
    main()
    